<?php

function connectToDatabase() {
    include 'dbInfo.php';

    $db_server = mysql_connect($host, $username, $password);
    if (!$db_server) {
        die("Cannot connect to server $host with username $username and password 
                $password<br />" . mysql_error());
    }
    $db_selected = mysql_select_db($database, $db_server);
    if (!$db_selected) {
        die("Cannot select database $database." . mysql_error());
    };

    return true;
}

/**
 * @desc Addes slashes to a string, and gets rid of HTML entities
 * @param string $str
 * @return string $str
 */
function sanitizeStr($str) {
    $str = strip_tags($str);
    $str = addslashes($str);
    return $str;
}

/**
 * @desc Removes slashes from a string
 * @param string $str
 * @return string $str
 */
function restoreStr($str) {
    $str = stripslashes($str);
    return $str;
}


/**
 * Hashes a given password
 * @param String Password to be hashed
 * @return String Returns the hashed password
 */
function encryptStr($str) {
    $str = crypt(md5($str), '$2a$13$6qpov45d80sd6f40DS465');
    $str = substr(strrchr($str, '.'), 1);
    return $str;
}

?>
